package com.btex.app.tools;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.View;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.btex.app.Config;
import com.btex.app.R;
import com.bumptech.glide.Glide;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * @author zhangyi<zhangyi, 1104745049@qq.com>
 * @version v1.0
 * @project study1
 * @Description
 * @encoding UTF-8
 * @date 2018/8/13
 * @time 下午4:48
 * @修改记录 <pre>
 * 版本       修改人         修改时间         修改内容描述
 * --------------------------------------------------
 * <p>
 * --------------------------------------------------
 * </pre>
 */


public class OTCBigImagDialog extends Dialog {
    private final Context context;
    private String mImag;
    @BindView(R.id.otc_full_imag)
    ImageView mOtcFullImag;
    @BindView(R.id.dialog_imag_big)
    LinearLayout mDialogImagBig;


    public OTCBigImagDialog(Context context, String imag) {
        super(context, R.style.otc_big_imag);
        this.context = context;
        mImag = imag;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.otc_big_imag_dialog);
        ButterKnife.bind(this);

        //获取屏幕宽高
        DisplayMetrics displayMetrics = getContext().getResources().getDisplayMetrics();
        //屏幕宽
        int widthPixels = displayMetrics.widthPixels;
        //屏幕高
        int heightPixels = displayMetrics.heightPixels;
        WindowManager.LayoutParams attributes = getWindow().getAttributes();
        //设置给attributes
        attributes.width = (int) (widthPixels * 0.9);
//        attributes.height = (int) (heightPixels * 0.6);
        //让Dialog位置居中
        attributes.gravity = Gravity.CENTER;
        getWindow().setAttributes(attributes);
        //点击空白处不dismiss
        setCanceledOnTouchOutside(true);

        Glide.with(context).load(Config.GETIMG + mImag).into(mOtcFullImag);


    }


    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {

        return super.onKeyDown(keyCode, event);
    }


    @OnClick({R.id.otc_full_imag, R.id.dialog_imag_big})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.otc_full_imag:
                dismiss();
                break;
            case R.id.dialog_imag_big:
                dismiss();
                break;
        }
    }
}
